package vno.fux.res.pool
{
	import flash.utils.Dictionary;
	import vno.fux.utils.HashSet;

	public class ResourceInventory
	{
		private static var _collection:Dictionary = new Dictionary;
		private var _properties:Object;
		private var _id:uint;
		public function ResourceInventory(id_:uint = uint.MAX_VALUE)
		{
			_id 		= id_;
			_properties = {"_map":new HashSet, "_character":new HashSet, "_ui":new HashSet, "_snd":new HashSet};
			if(id_!= uint.MAX_VALUE)
			{
				_collection[id_] = this;
			}
		}

		public static function getRI(id_:uint):ResourceInventory
		{
			var tmp:ResourceInventory = _collection[id_];
			if(!tmp)
			{
				throw new Error("ResourceInventory.getRI: Do not have the ResourceInventroy, id: "+id_);
			}
			return tmp;
		}
		public function intersect_(subtor:ResourceInventory):void
		{
			for(var prop:String in this._properties)
			{
				this._properties[prop].intersect_(subtor._properties[prop]);
			}
		}

		public function intersect(subtor:ResourceInventory):ResourceInventory
		{
			var tmp:ResourceInventory = this.clone();
			tmp.intersect_(subtor);
			return tmp;
		}

		private function clone():ResourceInventory
		{
			var tmp:ResourceInventory = new ResourceInventory;
			for(var prop:String in this._properties)
			{
				tmp._properties[prop] = this._properties[prop];
			}
			return tmp;
		}

		public function get map():HashSet
		{
			return _properties["_map"];
		}
		public function get character():HashSet
		{
			return _properties["_character"];
		}
		public function get ui():HashSet
		{
			return _properties["_ui"];
		}
		public function get snd():HashSet
		{
			return _properties["_snd"];
		}
	}
}